require 'rexml/document'
module FamilyTreeApi
  module Person
    module Assertion

      class Date
        attr_accessor :normalized, :original
        
        def ==(other)
          other.normalized == @normalized && other.original == @original
        end
        
        def to_xml
          e = REXML::Element.new('date')
          e.add_element('original').add_text(@original) if @original
          e.add_element('normalized').add_text(@normalized) if @normalized
          e
        end
        
        def self.parse(date_element)
          unless date_element.nil?
            date = self.new
            date_element.each do |e|
              date.normalized = e.content if e.name == 'normalized'
              date.original = e.content if e.name == 'original'
            end
            date
          end
        end
      end
      
    end
  end
end